<?php
 

class dao 
{

    function load($login,$password,$table) 
    {

         $query="select * from $table where login='$login' and password='$password'";
		 $result=mysql_query($query);
		 $count=mysql_num_rows($result);
			if ($count==1) return 1;
			else return 2;			
			  }
			  
    function confirmer_email($login,$email,$table) 
    {

         $query="select * from $table where login='$login' and email='$email'";
		 $result=mysql_query($query);
		 $count=mysql_num_rows($result);
			if ($count==1) 
			{
				while($ligne = mysql_fetch_row($result))
	 	$password= $ligne[2];
				
				mail($email,"RECUPERER VOTRE MOT DE PASSE ","voila votre mot de passe est:".$password);
				}
			else {
				$a="nn";
				return ($a);
				}			
			  }
			  
  function  recuperer_id($champ,$table,$predicat,$rech){

 $req="select $champ from $table where $predicat=\"".$rech."\"";
$result=mysql_query($req);
while($ligne=mysql_fetch_row($result)){
return $ligne[0];
}
}

	function  recuperer_ss($champ,$table,$predicat1,$predicat2,$rech1,$rech2){

 $req="select $champ from $table where $predicat1=$rech1 and $predicat2=$rech2";
$result=mysql_query($req);
while($ligne=mysql_fetch_row($result)){
return $ligne[0];
}

}
        
function  recuperer_rt($champ,$table,$predicat,$rech){

 $req="select $champ from $table where $predicat='$rech'";
 echo $req;
$result=mysql_query($req);
while($ligne=mysql_fetch_row($result)){
echo "
<tr><td>$ligne[2]</td>
<td>$ligne[3]</td>
<td>$ligne[1]</td>
<td>$ligne[11]</td>
<td>$ligne[12]</td>

<td><input type=\"checkbox\" name=\"id[]\" value=\"$ligne[0]\"/></td>
</tr>";

}
//echo $ligne[0];
}
function recuperer_rt_rech($req){
if($result=mysql_query($req)){
while($ligne=mysql_fetch_row($result)){
echo "
<tr class=\"tr1\"><td>$ligne[2]</td>
<td>$ligne[3]</td>
<td>$ligne[1]</td>
<td>$ligne[11]</td>
<td>$ligne[12]</td>

<td><a href=\"action_full.php?id_af=$ligne[0]\"><img src=\"../rechercher/icons/search.png\"></a></td>
</tr>";

}}}

function recuperer_rt_rech2($req){
if($result=mysql_query($req)){
while($ligne=mysql_fetch_row($result)){
echo "
<tr class=\"tr1\"><td>$ligne[2]</td>
<td>$ligne[3]</td>
<td>$ligne[1]</td>
<td>$ligne[11]</td>
<td>$ligne[12]</td>

<td><a href=\"action_full.php?id_af=$ligne[0]\"><img src=\"../../homepage/rechercher/icons/search.png\"></a>&#32;<a href=\"../organisme.php?id_af=$ligne[0]\"><img src=\"../../homepage/rechercher/icons/settings.png\"></a></td>
</tr>";

}}}

function  recuperer_rt2($requete){
if($result=mysql_query($requete)){
while($ligne=mysql_fetch_row($result)){
echo "
<tr><td>$ligne[2]</td>
<td>$ligne[3]</td>
<td>$ligne[1]</td>
<td>$ligne[11]</td>
<td>$ligne[12]</td>
<td>$ligne[1]</td>
<td>$ligne[6]</td>
<td><input type=\"checkbox\" name=\"id[]\" value=\"$ligne[0]\"/></td>
</tr>";

}}
//echo $ligne[0];
}
     
function loadAllAnnee(){
if($a=mysql_query('select annee from annee order by annee desc')){
		 while($ligne=mysql_fetch_row($a)){
		echo " <option> $ligne[0]</option>";
		 }
}	 }

function loadAllRecords($champ,$table){

 if($a=mysql_query("select  $champ from $table ")){
		 while($ligne=mysql_fetch_row($a)){
		echo " <option> $ligne[0]";
		 }}
}
function loadAllRecords2($champ,$table,$pr,$cn){

 if($a=mysql_query("select  $champ from $table where $pr=$cn")){
		 while($ligne=mysql_fetch_row($a)){
		echo " <option> $ligne[0]";
		 }}
}

 function agentverifier(){
	if(!isset($_SESSION['user'])||strcmp($_SESSION['user'],'agent')!=0)
	header('location:../index1.php');
	
}
 function agentverifier2(){
	if(!isset($_SESSION['user'])||strcmp($_SESSION['user'],'agent')!=0)
	header('location:../../index1.php');
	
}

 
function organismeverifier(){
	if(!isset($_SESSION['user'])||strcmp($_SESSION['user'],'organisme')!=0)
	header('location:../index1.php');
	
}
function organismeverifier2(){
	/*if(!isset($_SESSION['user'])||strcmp($_SESSION['user'],'organisme')!=0)
	header('location:../../index1.php');
	*/
}

function getId($login){
         $query="select num_org from organisme1 where login='$login'";
		 if($result=mysql_query($query)){
				while($ligne = mysql_fetch_row($result))
	 	$id= $ligne[0];
		return $id;
		}
		else return null;
		
}

function LoadAgentByCritique($req){
if($result=mysql_query($req)){
while($ligne=mysql_fetch_row($result)){
echo "
<tr class=\"tr1\"><td>$ligne[0]</td>
<td>$ligne[1]</td>
<td>$ligne[5]</td>
<td>$ligne[6]</td>
<td>$ligne[7]</td>
<td>$ligne[4]</td>

</tr>";

}}}
function load_id_action($name){
$query="select id_af from action where intitule='$name'";
if($result=mysql_query($query)){
while($ligne = mysql_fetch_row($result))
$id= $ligne[0];
return $id;
}}
}

   

?>